﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ApplLogic.ApplDbMediators;
using ApplLogic.ApplClasses;
using Utilities.GlobalData;
using Utilities.XmlReader;


namespace ApplLogic.LogicalServices
{
    public abstract class ApplRequestHandlerAbstract
    {
        
        public static ApplRequestHandlerAbstract FactoryMethod(eWorkingWithServerType workingType)
        {
            ApplRequestHandlerAbstract managerToCreate = null;
            switch(workingType)
            {
                case eWorkingWithServerType.Manager:
                    managerToCreate = new ApplManagerRequestHandler();
                    break;
                case eWorkingWithServerType.Worker:
                managerToCreate = new ApplWorkerRequestHandler();
                    break;
            }
            return managerToCreate;
        }

        public ApplWorkerStatInWeek GetWorkerStat(DateTime startTime, DateTime endTime, string workerId)
        {
            return ApplDbWorkerStatMediator.Instance.GetWorkerStat(startTime, endTime, workerId);
        }

        public string IsWorkerGotShift(string workerId, DateTime startTime, DateTime endTime)
        {
            return ApplDbResultMediator.Instance.IsWorkerGotShift(workerId, startTime, endTime) ? "Got" : "Not Got";
        }

        public ApplWorker ShowWorkerDetails(string workerId)
        {
            return ApplDbWorkerMediator.Instance.GetWorker(workerId);
        }

        public ApplShift ShowShiftDetails(string shiftId)
        {
            return ApplDbShiftMediator.Instance.GetShift(shiftId);
        }

        public ApplShift ShowShiftDetails(DateTime startTime, DateTime endTime)
        {
            return ApplDbShiftMediator.Instance.GetShiftByDateRange(startTime, endTime);
        }

        public List<ApplShift> GetAllShiftsThatWorkerAskedWithType(string workerId, eType type, DateTime startTime, DateTime endTime)
        {
            return ApplDbRequestMediator.Instance.GetAllShiftsThatWorkerAskedWithType(workerId, type, startTime, endTime);
        }

        public Dictionary<ApplShift, List<ApplSingleResult>> GetAllResultsOfAllShiftsOfWorker(DateTime startTime, DateTime endTime, string workerId)
        {
            return ApplDbResultMediator.Instance.GetAllResultsOfAllShiftsOfWorker(startTime, endTime, workerId);
        }

        public Dictionary<ApplShift, List<ApplSingleRequest>> GetAllRequestsOfAllShiftsOfWorker(DateTime startTime, DateTime endTime, string workerId)
        {
            return ApplDbRequestMediator.Instance.GetAllRequestsOfAllShiftsOfWorker(startTime, endTime, workerId);
        }

        public List<ApplShift> GetAllShiftsThatWorkerIsRegisteredToInStep(string workerId, eResult result, DateTime startTime, DateTime endTime)
        {
            return ApplDbResultMediator.Instance.GetAllShiftsWorkerGotWithStep(workerId, result, startTime, endTime);
        }

        public List<ApplShift> GetAllShiftsThatWorkerIsRegisteredTo(string workerId, DateTime startTime, DateTime endTime)
        {
            return ApplDbResultMediator.Instance.GetAllShiftsWorkerGot(workerId, startTime, endTime);
        }

        public List<ApplShift> GetAllShiftsThatWorkerAsked(string workerId, DateTime startTime, DateTime endTime)
        {
            return ApplDbRequestMediator.Instance.GetAllShiftsThatWorkerAsked(workerId, startTime, endTime);
        }

        public ApplWorkerStatInWeek GetAllWorkerStatOfWorker(string workerId)
        {
            return ApplDbWorkerStatMediator.Instance.GetAllWorkerStatOfWorker(workerId);
        }

        public void RenterAllRequestsOfWorker(string workerId, DateTime startTime, DateTime endTime, List<ApplSingleRequest> newRequests)
        {
            ApplDbRequestMediator.Instance.RenterAllRequestsOfWorker(workerId, startTime, endTime, newRequests, true);
        }

        public ApplWorker GetWorkerById(string workerId)
        {
            return ApplDbWorkerMediator.Instance.GetWorker(workerId);
        }
                        
        public string GetNumberOfWorkersPerShift()
        {
            return MyXmlReader.GetValueOfGeneralSetting(               
               eGeneralSettingName.NumberOfWorkersPerShift);
        }

        public string GetDefaultPeriodBetweenShiftsForRunningAlgo()
        {
            return MyXmlReader.GetValueOfSingleConstraint (               
                eConstraints.PERIODBETWEENSHIFTS);
        }

        public string GetMinNumberOfShiftsPerDay()
        {
            return MyXmlReader.GetValueOfSingleConstraint(
                eConstraints.MINNUMOFSHIFTSFORWORKER);
        }

        public string GetLenghtOfShift()
        {
            return MyXmlReader.GetValueOfGeneralSetting(
                eGeneralSettingName.LenghtOfShiftInHours);
        }

        public string GetNumberOfShiftsPerDay()
        {
            return MyXmlReader.GetValueOfGeneralSetting(
                    eGeneralSettingName.NumberOfShiftsPerDay);
        }

        public string GetStartTimeOfWork()
        {
            return MyXmlReader.GetValueOfGeneralSetting(
                    eGeneralSettingName.StartTimeOfWork);
        }


    }
}
